package com.hdax.dm.mapstucts;

import com.hdax.dm.beans.order.order;
import com.hdax.dm.dto.queryorderlistDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Mapper(componentModel = "Spring")
public abstract class queryorderlistDtoMapper {

    protected String calcTime(LocalDateTime createdTime){
        LocalDateTime endTime = createdTime.plusMinutes(15L);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return dateTimeFormatter.format(endTime);
    }

    @Mappings({
            @Mapping(source = "createdTime", target = "sellTime"),
            @Mapping(source = "totalCount", target = "num"),
            @Mapping(source = "insuranceAmount", target = "unitPrice"),
            @Mapping(target = "endTime", expression = "java(calcTime(source.getCreatedTime()))")
    })
    public abstract queryorderlistDto toTarget(order source);

    public abstract List<queryorderlistDto> toTargetList(List<order> sources);
}
